package day8;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {

	@Test
	public void test1() {
		
	}
	
	public static void main(String[] args) {
		String str = "----";
		System.out.println(trim(str));
	}
	
	public static String trim(String str) {
		int start = 0;
	  	int end = str.length() - 1;
		while (start <= end && str.charAt(start) == '-') {
			start++;
		}
		while (start <= end && str.charAt(end) == '-') {
			end--;
		}
		return str.substring(start, end + 1);
	}
	
	
	public static void main3(String[] args) {
		String string = "---";
		char[] chs = string.toCharArray();
		int start = 0;
		int end = 0;
		
		for (int i = 0; i < chs.length; i++) {
			if(chs[i] != '-') {
				start = i;
				break;
			}
		}
		for (int i = chs.length - 1; i >= 0; i--) {
			if(chs[i] != '-') {
				end = i + 1;
				break;
			}
		}
		
		System.out.println(string.substring(start, end));
	}
	
	@Test
	public void trim() {
		String str = " Java Android    ";
		str.trim();
		int start = 0;
		int end = str.length() - 1;
		char[] array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			if (array[i] == ' ') {
				start++;
			}else {
				break;
			}
		}
		
		for (int i = str.length()-1; i >= 0; i--) {
			if (array[i] == ' ') {
				end--;
			}else {
				break;
			}
		}
		System.out.println("start：" + start);
		System.out.println("end：" + end);
		str = str.substring(start, end + 1);
		System.out.println("substring(3,15)：" +  str);
	}
	
	@Test
	//实现把“I Love Java！”的字符全部转换为小写并输出到控制台。
	public void test13() {
		String str = "I Love Java！" ;
		char[] array = str.toCharArray();
		for(int i = 0; i < array.length; i++) {
			if(array[i] >= 'A' && array[i] <= 'Z') {
				// array[i] =  (char)(array[i] + 32);
				array[i] += 32;
				// array[i] = array[i] + 32;
			}
		}
		String str2 = String.valueOf(array);
		System.out.println(str2);
	}
	
	// this is my homework! I must finish it!
	@Test
	public void test33() {
		String str = "this is my homework! I must finish it!";
		String[] array = str.split(" ");
		System.out.println(array.length);
		for (String string : array) {
			System.out.println(string);
		}
	}
	
}
